layui.define(['LDUtils', 'carousel'], function(exports){
    var carousel = layui.carousel,
        LDUtils = layui.LDUtils;
    function LDCarousel () {
    }

    LDCarousel.prototype.init = function (option) {
        var defOption = {
            elem: '',
            width: '100%',
            arrow: 'none',
            indicator: 'none',
            anim: 'fade',
            height: '584px',
            autoplay: true,
            interval: 6000
        }
        var config = LDUtils.assign(defOption, option)
        this.ins = carousel.render(config);
        this.caroucel = carousel;
        this.bindEvent();
        return this;
    }

    LDCarousel.prototype.bindEvent = function () {
        var $action = $('#carousel_action_hook');
        if (!$action.length) return;
        var _this = this;
        $action.delegate('.arrow-previous', {
            click: function () {
                // 上一页
                _this.ins.slide('sub');
            }
        }).delegate('.arrow-next', {
            click: function () {
                // 下一页
                _this.ins.slide('add');
            }
        })
    }
    // 导出模块
    exports('LDCarousel', LDCarousel);
});